home *** CD-ROM | disk | FTP | other *** search
- /*
- File: BigBrains.cp
-
- Contains: Application-specific code for BigBrains.
-
- Written by: Kent Miller
-
- Copyright: © 1995-1996 by Kent Miller, all rights reserved.
-
- Change History (most recent first):
-
- */
-
- #include <Displays.h>
-
- //Sprocket Includes
- #include "Sprocket.h"
-
- //App specific includes
- #include "SuperFly.h"
- #include "SuperFlyAppleEventHandler.h"
- #include "GDeviceUtilities.h"
- #include "GDeviceWindow.h"
- #include "SuperFlyToolWindow.h"
-
- //Application specific globals
- TLinkedList *gMyWindowList; //One for every active GDevice
- TSuperFlyToolWindow *gMyToolWindow = nil;
- Boolean gMirroringWasOn; //Was mirroring on when I started?
- Boolean gHasTranslucentDrag;
-
- OSErr
- SetupApplication(void)
- {
- OSErr err = noErr;
- SInt32 result;
-
- if (!gHasDisplayManager)
- {
- ErrorAlert(kErrorList, kNoDisplayManager);
- gDone = true;
- return -1;
- }
-
- if (!gHasColorQuickdraw)
- {
- ErrorAlert(kErrorList, kNoColorQD);
- gDone = true;
- return -1;
- }
-
- err = InstallDisplayManagerEventHandler();
- DMIsMirroringOn(&gMirroringWasOn);
-
- gMyToolWindow = new TSuperFlyToolWindow();
-
- if ((gHasDragManager) && (noErr == Gestalt(gestaltDragMgrAttr, &result)) )
- gHasTranslucentDrag = result & 0x08;
-
- InitCursor();
- return err;
- }
-
-
- void
- TearDownApplication(void)
- {
- Boolean mirroringOnNow;
-
- SuperFlyTearDownMyWindows();
-
- DMIsMirroringOn(&mirroringOnNow);
- if (gMirroringWasOn != mirroringOnNow)
- MirrorAllDisplays(gMirroringWasOn); //Toggle state of mirroring
- }
-
- void
- HandleMenuCommand(MenuCommandID theCommand)
- {
- switch (theCommand)
- {
- case cAbout:
- AboutBox();
- break;
-
- case cMirroring:
- Boolean mirroringOnNow;
-
- DMIsMirroringOn(&mirroringOnNow);
- MirrorAllDisplays(!mirroringOnNow); //Toggle state of mirroring
- break;
-
- case cOpen:
- break;
-
- case cPageSetup:
- break;
-
- case cPrint:
- break;
-
- case cQuit:
- gDone = true;
- break;
-
- case cCopy:
- case cCut:
- case cPaste:
- case cClear:
- break;
-
- default:
- break;
- }
- }
-
- void
- HandleMenuSelection(MenuID /* theMenu */,MenuItemID /* theItem */)
- {
- }
-
-
- void
- WriteLocalClipboardToScrap(void)
- {
- TEToScrap();
- }
-
- void
- ReadLocalClipboardFromScrap(void)
- {
- TEFromScrap();
- }
-
-
- OSErr
- CreateNewDocument(void)
- {
- if (!gMyWindowList)
- SuperFlySetUpWindows();
-
- return noErr;
- }
-
-
- OSErr
- OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
- {
- return errAEEventNotHandled;
- }
-
-
- OSErr
- PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
- {
- return errAEEventNotHandled;
- }
-
-
- Boolean
- QuitApplication(void)
- {
- return true;
- }
-
-
-
- /**********************
- Above this line are functions required by Sprocket. Below this line is
- support routines for those routines.
- ***********************/
-
- void AboutBox(void)
- {
- EventRecord e;
- Boolean wasVisible;
-
- if (gMyToolWindow)
- {
- wasVisible = gMyToolWindow->IsVisible();
- if (wasVisible)
- gMyToolWindow->ShowHide(false);
- }
- gSplashWindow = new TSplashWindow;
- HiliteMenu(0);
- do {
- WaitNextEvent(everyEvent,&e,60,gMouseRegion);
- }while (( e.what != mouseDown) && (e.what != keyDown));
- delete gSplashWindow; // get rid of the splash screen
-
- if (gMyToolWindow)
- {
- if (wasVisible)
- gMyToolWindow->ShowHide(true);
- }
- }
-
-
- void
- SuperFlyTearDownMyWindows(void)
- {
- TGDeviceWindow *theWin;
-
- theWin = (TGDeviceWindow *)gMyWindowList->GetFirstListElem();
- while (theWin)
- {
- gMyWindowList->RemoveFromList(theWin);
- theWin->Close();
- theWin = (TGDeviceWindow *)gMyWindowList->GetFirstListElem();
- }
- delete gMyWindowList;
- }
-
- OSErr
- SuperFlySetUpWindows(void)
- {
- GDHandle theGD;
- TGDeviceWindow *newWin;
- TLinkedList *myGDList;
-
- if (gMyWindowList)
- SuperFlyTearDownMyWindows();
-
- myGDList = BuildAListOfUniqueDevices();
-
- gMyWindowList = new TLinkedList;
-
- theGD = (GDHandle) myGDList->GetFirstListElem();
- while (theGD)
- {
- newWin = new TGDeviceWindow;
- gMyWindowList->AddToList( newWin );
- newWin->SetUpData( theGD );
- theGD = (GDHandle) myGDList->GetNextListElem( theGD );
- }
-
- delete myGDList;
-
- return noErr;
- }
-
- void
- SuperFlyHandleGDevicesMoved(void)
- //This function is called by the Display Manager Apple Event handler in AppleEventHandling.cp.
- //It's purpose is to loop through the currently active windows and ensure that each window is still
- //completely on it's device. If it isn't, it will center the window on it's device.
- //
- //If your application doesn't set the Display Manager Aware bit in it's size resource,
- //the Display Manager will move the windows for you. You just can't be sure where they will
- //end up.
- {
- TGDeviceWindow *theWin;
-
- theWin = (TGDeviceWindow *) gMyWindowList->GetFirstListElem();
-
- while (theWin)
- {
- theWin->WindowOnDevice();
- theWin = (TGDeviceWindow *) gMyWindowList->GetNextListElem(theWin);
- }
-
- if (gMyToolWindow)
- gMyToolWindow->MoveToRelativePosition();
- }
-